package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.blnorulepbcodevo.BlnoRulePbcodeCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnorulepbcodevo.BlnoRulePbcodePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnorulepbcodevo.BlnoRulePbcodeRespVO;
import com.cmc.cloud.cmclink.doc.vo.blnorulepbcodevo.BlnoRulePbcodeUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.BlnoRulePbcodeDO;
import com.cmc.cloud.cmclink.doc.service.BlnoRulePbcodeService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 接货地提单号两位码")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/pbCode")
@Validated
public class BlnoRulePbcodeController {

    @Resource
    private BlnoRulePbcodeService blnoRulePbcodeService;

    @Operation(summary = "创建接货地提单号两位码")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:departurePlaceTwoCode:add')")
    public CommonResult<Void> createBlnoRulePbcode(@Valid @RequestBody BlnoRulePbcodeCreateReqVO createReqVO) {
        blnoRulePbcodeService.createBlnoRulePbcode(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新接货地提单号两位码")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:departurePlaceTwoCode:edit','doc:departurePlaceTwoCode:enable'})")
    public CommonResult<Void> updateBlnoRulePbcode(@Valid @RequestBody BlnoRulePbcodeUpdateReqVO updateReqVO) {
        blnoRulePbcodeService.updateBlnoRulePbcode(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除接货地提单号两位码")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:departurePlaceTwoCode:delete')")
    public CommonResult<Void> deleteBlnoRulePbcode(@PathVariable("id") Long id) {
        blnoRulePbcodeService.deleteBlnoRulePbcode(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得接货地提单号两位码")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("getById/{id}")
    public CommonResult<BlnoRulePbcodeRespVO> getBlnoRulePbcode(@PathVariable("id") Long id) {
        BlnoRulePbcodeDO blnoRulePbcode = blnoRulePbcodeService.getBlnoRulePbcode(id);
        return CommonResult.success(BeanUtil.copyProperties(blnoRulePbcode, BlnoRulePbcodeRespVO.class));
    }

    @Operation(summary = "获得接货地提单号两位码列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<BlnoRulePbcodeRespVO>> getBlnoRulePbcodeList(@RequestParam("ids") Collection<Long> ids) {
        List<BlnoRulePbcodeDO> list = blnoRulePbcodeService.getBlnoRulePbcodeList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,BlnoRulePbcodeRespVO.class));
    }

    @Operation(summary = "获得接货地提单号两位码分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:departurePlaceTwoCode:search')")
    public CommonResult<PageResult<BlnoRulePbcodeRespVO>> getBlnoRulePbcodePage(@Valid @RequestBody BlnoRulePbcodePageReqVO pageVO) {
        PageResult<BlnoRulePbcodeRespVO> pageResult = blnoRulePbcodeService.getBlnoRulePbcodePage(pageVO);
        return CommonResult.success(pageResult);
    }
}
